package com.view;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

import com.mode.Shape;
import com.mode.ShapeFactory;
import com.mode.Wall;

public class GamePn extends JPanel implements Observer{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Shape shape;
	private Wall wall;
	
	public GamePn(Wall wall) {
		this.setBorder(BorderFactory.createLoweredBevelBorder());
		this.wall=wall;
	}

	@Override
	public void paint(Graphics g) {
		// TODO Auto-generated method stub
		super.paint(g);
		
		if(shape==null){
			return;
		}
		
		int[][] oneShape=shape.getShape();
		int x=shape.getX(),y=shape.getY();
		if(y>20){
			wall.save(shape);
		}
		for(int i=0;i<oneShape.length;i++){
			for(int j=0;j<oneShape[i].length;j++){
				if(oneShape[i][j]==1){
					g.setColor(Color.BLUE);
					g.fill3DRect(x*ShapeFactory.NODEWIDTH+j*ShapeFactory.NODEWIDTH, y*ShapeFactory.NODEHEIGHT+i*ShapeFactory.NODEHEIGHT, ShapeFactory.NODEWIDTH, ShapeFactory.NODEHEIGHT, true);
				}
			}
		}
		
		int[][] walls=wall.getWall();
		for(int i=0;i<walls.length;i++){
			for(int j=0;j<walls[i].length;j++){
				if(walls[i][j]==1){
					System.out.println("123");
					g.setColor(Color.yellow);
					g.fill3DRect(j * ShapeFactory.NODEWIDTH, i * ShapeFactory.NODEHEIGHT, ShapeFactory.NODEWIDTH,ShapeFactory.NODEHEIGHT, true);
				}
			}
		}
	}
	
	
	@Override
	public void update(Observable arg0, Object arg1) {
		shape=(Shape) arg1;
		repaint();
	}
}
